package jianzhi

func deleteNode(head *ListNode, val int) *ListNode {
	if head == nil {
		return head
	}

	if head.Val == val {
		return head.Next
	}

	for temp := head; temp != nil; temp = temp.Next {
		if temp.Next.Val == val {
			if temp.Next != nil {
				temp.Next = temp.Next.Next
			} else {
				temp.Next = nil
			}
		}
	}

	return head
}
